package com.xiaoyao.wblog.activity;

import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.util.Log;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.widget.ImageView;

import com.xiaoyao.wblog.R;

public class SplashActivity extends Activity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.splash);

		// 获取图片view
		ImageView imageView = (ImageView) this.findViewById(R.id.bg_image);
		
		// 生成一个动画实例
		AlphaAnimation alphaAnim = new AlphaAnimation(0.1f, 1.0f);
		alphaAnim.setDuration(4000);
		alphaAnim.setAnimationListener(new AnimationListener() {

			@Override
			public void onAnimationEnd(Animation arg0) {
				// 动画结束后，启动程序主界面Activity
				Intent it = new Intent(SplashActivity.this, LoginActivity.class);
				startActivity(it);
				// 将当前Activity给finish掉，否则当用户按返回键的话, 是会重新进入到该Activity中的
				finish();
			}

			@Override
			public void onAnimationRepeat(Animation animation) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onAnimationStart(Animation animation) {
				// TODO Auto-generated method stub

			}

		});
		
		// 为图片view设置动画
		imageView.startAnimation(alphaAnim);

	}

	@Override
	public void onConfigurationChanged(Configuration newConfig) {
		super.onConfigurationChanged(newConfig);
		// getWindow().setBackgroundDrawableResource(R.drawable.splash);
		setContentView(R.layout.splash);
	}

}